<%@ page import="studentinformationmanagementsystem.entity.Student" %>

<%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">--%>
<%--<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">--%>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%Student studentlogin = (Student)request.getSession().getAttribute("Studentlogin");%>
	学生信息管理平台
</title>
    <link href="../../style/StudentStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../script/jBox/Skins/Blue/jbox.css" rel="stylesheet" type="text/css" />
    <link href="../../style/ks.css" rel="stylesheet" type="text/css" />
    <script src="../../script/jBox/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="../../script/jBox/jquery.jBox-2.3.min.js" type="text/javascript"></script>
    <script src="../../script/jBox/i18n/jquery.jBox-zh-CN.js" type="text/javascript"></script>
    <script src="../../script/Common.js" type="text/javascript"></script>
    <script src="../../script/Data.js" type="text/javascript"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
    <script type="text/javascript">
        $().ready(function () {
            setStudMsgHeadTabCheck();
            showUnreadSysMsgCount();
        });

        //我的信息头部选项卡
        function setStudMsgHeadTabCheck() {
            var currentUrl = window.location.href;
            currentUrl = currentUrl.toLowerCase();
            var asmhm = "";
            $("#ulStudMsgHeadTab li").each(function () {
                asmhm = $(this).find('a').attr("href").toLowerCase();
                if (currentUrl.indexOf(asmhm) > 0) {
                    $(this).find('a').attr("class", "tab1");
                    return;
                }
            });
        }

        //显示未读系统信息
        function showUnreadSysMsgCount() {
            var unreadSysMsgCount = "0";
            if (Number(unreadSysMsgCount) > 0) {
                $("#unreadSysMsgCount").html("(" + unreadSysMsgCount + ")");
            }
        }

        //退出
        function loginOut() {
            if (confirm("确定退出吗？")) {
                StudentLogin.loginOut(function (data) {
                    if (data == "true") {
                        window.location = "/Login.aspx";
                    }
                    else {
                        jBox.alert("退出失败！", "提示", new { buttons: { "确定": true} });
                    }
                });
            }
        }
        //更改报考类别
        function changeCateory(thisObj, id) {
            var oldCateoryId = $("#cateoryId").val();
            var cateoryId = "";
            if (id != null) {
                cateoryId = id;
            }
            else {
                cateoryId = thisObj.val();
            }
            var studentId = $("#studentId").val();
            if (cateoryId.length &lt;= 0) {
                jBox.tip("报考类别不能为空！");
                if (id == null) {
                    thisObj.val(oldCateoryId);
                }
            }
            else {
                studentInfo.changeStudentCateory(cateoryId, function (data) {
                    var result = $.parseJSON(data);
                    if ((String(result.ok) == "true")) {
                        window.location.href = "/Index.aspx";
                    }
                    else {
                        jBox.tip(result.message);
                    }
                });
            }
        }
    </script>
    
<script type="text/javascript" language="javascript">

</script>
<style type="text/css">
    .txtinput1{width:180px;}
</style>
</head>
<body>

<div class="banner">
    <div class="bgh">
        <div class="page">
            <div id="logo">
                <a href="../../Index.aspx.jsp">
                    <img src="../../images/Student/logo.gif" alt="" width="165" height="48" />
                </a>
            </div>
            <div class="topxx"><%=studentlogin.getStudentid()%>学员：<%=studentlogin.getStudentname()%>，欢迎您！
                <a href="../../myinfo/Index.aspx.jsp">我的信息</a>
<%--                <a href="../../user/studentinfor/SystemMsge.aspx.jsp">通知</a>--%>
                <a href="../account/ChangePasswd.aspx.jsp">密码修改</a>
                <a href="../../../../student1/login.do?action=NoStudenLogin">安全退出</a>
            </div>
            <div class="blog_nav">
                <ul>
                    <li><a href="../../myinfo/Index.aspx.jsp">我的信息</a></li>
                    <li><a href="../../educationcenter/Application.aspx.jsp">教务中心</a></li>
<%--                    <li><a href="../../myaccount/wdcw.aspx.jsp">我的学费</a></li>--%>
<%--                    <li><a href="../../onlineteaching/StudentMaterial.aspx.jsp">资料中心</a></li>--%>
                </ul>
            </div>
        </div>
    </div>
</div>

    <div class="page">
        <div class="box mtop">
            <div class="leftbox">
                <div class="l_nav2">
                    <div class="ta1">
                        <strong>个人中心</strong>
                        <div class="leftbgbt">
                        </div>
                    </div>
                    <div class="cdlist">
                        <div>
                            <a href="../../myinfo/Index.aspx.jsp">我的信息</a></div>
                        <div>
                            <a href="../../myinfo/ClassInfo.aspx.jsp">班级信息 </a>
                        </div>
<!--                        <div>-->
<!--                            <a href="../studentinfor/Letter.aspx.html">短信息</a></div>-->
<%--                        <div>--%>
<%--                            <a href="../studentinfor/SystemMsge.aspx.jsp">学院通知</a></div>--%>
<!--                        <div>-->
<!--                            <a href="../../myinfo/Objection.aspx.jsp">我的异议</a></div>-->
                    </div>
                    <div class="ta1">
                        <strong>教务中心</strong>
                        <div class="leftbgbt2">
                        </div>
                    </div>
                    <div class="cdlist">
                        <div>
                            <a href="../../educationcenter/Application.aspx.jsp">选课</a></div>
                        <div>
                            <a href="../../educationcenter/Book.aspx.jsp">我的选课</a></div>
<%--                        <div>--%>
<%--                            <a href="../../educationcenter/Score.aspx.jsp">我的成绩</a>--%>
<%--                        </div>--%>

                        <div>
                            <a href="../../educationcenter/Classschedule.jsp">我的课表</a>
                        </div>

                    </div>
<%--                    <div class="ta1">--%>
<%--                        <strong>学习中心</strong><div class="leftbgbt2">--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                    <div class="cdlist">--%>
<%--                        <div>--%>
<%--                            <a href="../../onlineteaching/StudentMaterial.aspx.jsp">资料下载</a></div>--%>
<%--                        <div>--%>
<%--                            <a href="../../onlineteaching/StudentStudyRecordList.aspx.jsp">学习历程</a></div>--%>
<%--                    </div>--%>
                   
<%--                    <div class="ta1">--%>
<%--                        <strong>财务中心</strong><div class="leftbgbt2">--%>
<%--                        </div>--%>
<%--                    </div>--%>
<%--                    <div class="cdlist">--%>
<%--                        <div>--%>
<%--                            <a href="../../myaccount/wdcw.aspx.jsp">我的财务</a></div>--%>
<%--                    </div>--%>
<%--                        <div class="ta1">--%>
<%--                         <strong>教学系统</strong>--%>
<%--                        <div class="leftbgbt2">--%>
<%--                        </div>--%>
<%--                    </div>--%>
                </div>
            </div>
            <div class="rightbox">
                
<h2 class="mbx">我的信息 &gt; 密码修改</h2>
<div class="cztable">
<table border="0" cellspacing="0" cellpadding="0" width="500px" style="margin:30px auto 0px auto;">
    <tr align="center">
        <th style="width:20%; text-align:left;">旧密码：</th>
        <td style="width:70%; text-align:left;">
            <input id="txtOldPwd" value="" type="password" class="input_2 txtinput1" />
        </td>
    </tr>
    <tr align="center">
        <th style="width:20%; text-align:left;">新密码：</th>
        <td style="width:70%; text-align:left;"><input id="txtNewPwd" value="" type="password" class="input_2 txtinput1" />&nbsp;&nbsp;6~16个字符，区分大小写</td>
    </tr>
    <tr align="center">
        <th style="width:20%; text-align:left;">确认新密码：</th>
        <td style="width:70%; text-align:left;"><input id="txtConfirmNewPwd" value="" type="password" class="input_2 txtinput1" /></td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:center;">
        <input type="submit" id="btnSubmit" value="确认修改" onclick="changePassword()" class="input2" />
<%--        <button class="btn btn-danger"data-toggle="modal" data-target="#productModal" onclick="changePassword()">确认</button>--%>
    </td>
    </tr>
</table>
</div>

            </div>
        </div>
    </div>


<script>



    //旧密码的格式验证
    $('#txtOldPwd').blur(function () {

        var oldPwd = $("#txtOldPwd").val();
        var ereg=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
        if (oldPwd=="" || $.trim(oldPwd)==null || $.trim(oldPwd) ==''){

            $.jBox.tip("旧密码不能为空！", 'error');

        }else if (!ereg.test(oldPwd)){

            $.jBox.tip("旧密码格式不正确，密码要包含数字和英文，长度为6-20！", 'error');

        }

    })


    //新密码的格式验证
    $('#txtNewPwd').blur(function () {

        var txtNewPwd = $("#txtNewPwd").val();

        var ereg=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;

        if (txtNewPwd=="" || $.trim(txtNewPwd)==null || $.trim(txtNewPwd) ==''){

            $.jBox.tip("新密码不能为空！", 'error');

        }else if (!ereg.test(txtNewPwd)){

            $.jBox.tip("新密码格式不正确，密码要包含数字和英文，长度为6-20！", 'error');

        }

    })

    //确认的新密码格式验证
    $('#txtConfirmNewPwd').blur(function () {
        var txtConfirmNewPwd = $("#txtConfirmNewPwd").val();

        var ereg=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
        if (txtConfirmNewPwd=="" || $.trim(txtConfirmNewPwd)==null || $.trim(txtConfirmNewPwd) ==''){

            $.jBox.tip("确认新密码不能为空！", 'error');

            return false;
        }else if (!ereg.test(txtConfirmNewPwd)){

            $.jBox.tip("确认新密码格式不正确，密码要包含数字和英文，长度为6-20！", 'error');

            return false;
        }
    })




    function changePassword() {


        var oldPwd = $("#txtOldPwd").val();
        var newPwd = $("#txtNewPwd").val();
        var confirmNewPwd = $("#txtConfirmNewPwd").val();




         //旧密码格式验证
        var ereg3=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
        if (oldPwd=="" || $.trim(oldPwd)==null || $.trim(oldPwd) ==''){

            $.jBox.tip("旧密码不能为空！", 'error');
            return false;
        }else if (!ereg3.test(oldPwd)){

            $.jBox.tip("旧密码格式不正确，密码要包含数字和英文，长度为6-20！", 'error');
            return false;
        }




        //新密码格式验证
        var ereg1=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;

        if (newPwd=="" || $.trim(newPwd)==null || $.trim(newPwd) ==''){

            $.jBox.tip("新密码不能为空！", 'error');
            return false;
        }else if (!ereg1.test(newPwd)){

            $.jBox.tip("新密码格式不正确，密码要包含数字和英文，长度为6-20！", 'error');
            return false;
        }


        //确认新密码格式验证
        var ereg=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;
        if (confirmNewPwd=="" || $.trim(confirmNewPwd)==null || $.trim(confirmNewPwd) ==''){

            $.jBox.tip("确认新密码不能为空！", 'error');

            return false;
        }else if (!ereg.test(confirmNewPwd)){

            $.jBox.tip("确认新密码格式不正确，密码要包含数字和英文，长度为6-20！", 'error');

            return false;
        }











        //比较两次输入值是否相同
        if (newPwd !== confirmNewPwd) {

            $.jBox.tip("新密码两次输入不一致！", 'error');

            return false;
        }


        $.ajax({
            //接收路径
            url: '../../../../student1/StudentServlet.do',
            type: 'POST',
            dataType: 'text',
            data: {
                formerpassword:oldPwd,
                newpassword:newPwd,
                confirmpassword:confirmNewPwd,
                action:'changePassword'
            },
            success:function (data) {  //响应成功获取响应返回的值

                if (data==='0'){

                    swal({
                        title : "修改密码提示信息",
                        type : "error",
                        text : "输入的旧密码不正确",
                        confirmButtonText : "确定",
                        closeOnConfirm : false
                    });

                }else if (data==='1'){

                    swal({
                        title : "修改密码提示信息",
                        type : "error",
                        text : "新密码两次输入的不一致",
                        confirmButtonText : "确定",
                        closeOnConfirm : false
                    });

                }else if (data==='2'){

                    swal({
                        title : "修改密码提示信息",
                        type : "error",
                        text : "修改密码成功,请重新登陆",
                        confirmButtonText : "确定",
                        closeOnConfirm : false
                    }).then(function () {
                        //返回登陆页面
                        window.location.href = "../../../log/Login.html"
                    });

                }else {

                    swal({
                        title : "修改密码提示信息",
                        type : "error",
                        text : "修改密码失败",
                        confirmButtonText : "确定",
                        closeOnConfirm : false
                    });

                }
            },error: function (err) {  //响应失败

                swal({
                    title : "修改密码提示信息",
                    type : "error",
                    text : "密码修改失败",
                    confirmButtonText : "确定",
                    closeOnConfirm : false
                });

            }
        });




    }


</script>

</body>
</html>
